package com.mentalhealthplatform.global.rbac.controller;

import com.mentalhealthplatform.global.rbac.dto.normal.ButtonComponentDTO;
import com.mentalhealthplatform.global.rbac.service.entity.ButtonComponentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/buttons")
public class ButtonController {

    @Autowired
    private ButtonComponentService buttonService;

    @PostMapping
    public ButtonComponentDTO createButton(@RequestBody ButtonComponentDTO buttonComponentDTO) {
        return buttonService.createButton(buttonComponentDTO);
    }

    @PutMapping("/{id}")
    public ButtonComponentDTO updateButton(@PathVariable Long id, @RequestBody ButtonComponentDTO buttonComponentDTO) {
        return buttonService.updateButton(id, buttonComponentDTO);
    }

    @DeleteMapping("/{id}")
    public void deleteButton(@PathVariable Long id) {
        buttonService.deleteButton(id);
    }

    @PatchMapping("/{id}/toggle-status")
    public void toggleStatus(@PathVariable Long id) {
        buttonService.toggleButtonStatus(id);
    }

    @PatchMapping("/{id}/toggle-visibility")
    public void toggleVisibility(@PathVariable Long id) {
        buttonService.toggleButtonVisibility(id);
    }

    @PostMapping("/{id}/associate-endpoints")
    public void associateEndpoints(@PathVariable Long id, @RequestBody List<Long> endpointIds) {
        buttonService.associateEndpoints(id, endpointIds);
    }

    @DeleteMapping("/{id}/unassociate-endpoints")
    public void unassociateEndpoints(@PathVariable Long id, @RequestBody List<Long> endpointIds) {
        buttonService.unassociateEndpoints(id, endpointIds);
    }
}
